package addBinary;

public class Solution {
    public String addBinary(String a, String b) {
        // 二进制求和
        StringBuilder ans = new StringBuilder();
        int i = a.length()-1;
        int j = b.length()-1;
        int t = 0; // 表示进位
        while (i>=0||j>=0||t!=0) {
            int sum = t;
            if(i>=0) sum+=(a.charAt(i--)-'0');
            if(j>=0) sum+=(b.charAt(j--)-'0');
            ans.append(sum%2);
            t = sum/2;
        }
        return ans.reverse().toString();
    }
}
